import 'package:flutter/material.dart';
import 'package:flutter_house_manager/pages/Home/index.dart';
import 'package:flutter_house_manager/pages/Mine/index.dart';

class TabsPage extends StatefulWidget {
  const TabsPage({super.key});

  @override
  State<TabsPage> createState() => _TabsPageState();
}

class _TabsPageState extends State<TabsPage> {
  // 默认索引
  int _currentIndex = 0;
  // 底部导航栏图标
  final List _tabs = [
    {
      "label": '首页',
      "icon": "assets/tabs/home_default.png",
      "active_icon": "assets/tabs/home_active.png"
    },
    {
      "label": '我的',
      "icon": "assets/tabs/my_default.png",
      "active_icon": "assets/tabs/my_active.png"
    }
  ];
  // 返回底部Tabs中的item
  List<BottomNavigationBarItem> getTabsBar() {
    List<BottomNavigationBarItem> list = [];
    for (var item in _tabs) {
      list.add(BottomNavigationBarItem(
        icon: Image.asset(
          item["icon"] as String,
          width: 30,
          height: 30,
        ),
        activeIcon: Image.asset(
          item["active_icon"] as String,
          width: 30,
          height: 30,
        ),
        label: item["label"] as String,
      ));
    }
    return list;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: IndexedStack(
          index: _currentIndex,
          children: const [
            HomePage(),
            MyPage(),
          ],
        ),
      ),
      bottomNavigationBar: BottomNavigationBar(
        selectedItemColor: const Color.fromARGB(255, 85, 145, 175),
        unselectedItemColor: const Color.fromARGB(255, 128, 128, 128),
        items: getTabsBar(),
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),
    );
  }
}
